<?php
namespace App\Admin\Controllers\OverSeasBa;

use App\Models\OverSeasBa\WarehouseGroup;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Form;
use Encore\Admin\Grid;
class WarehouseGroupController extends AdminController{

    protected $title = '海外仓运营商';

    protected function grid()
    {
        $grid = new Grid(new WarehouseGroup());
        $grid->model()->orderBy('id', 'DESC');
        $grid->column('id','ID');
        $grid->column('name','海外仓名');
        if(Admin::user()->can('os-ba.warehouse-group.edit')){
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->disableView();
                $actions->disableDelete();
            });
            $grid->quickCreate(function (Grid\Tools\QuickCreate $create) {
                $create->text('name', '海外仓名');
            });
        }else{
            $grid->disableActions();
            $grid->disableCreateButton();
        }

        $grid->disableFilter();
        $grid->disableExport();
        $grid->disableCreateButton();
        $grid->quickSearch('name');

        return $grid;
    }

    public function form()
    {
        $form = new Form(new WarehouseGroup());

        $form->hidden('id');

        $form->text('name', '海外仓')
            ->setWidth(3)
            ->creationRules(['required', "unique:os_b_warehouse_group"],['required' => '海外仓名必填','unique' => '海外仓名已存在'])
            ->updateRules(['required', "unique:os_b_warehouse_group,name,{{id}}"],['required' => '海外仓名必填','unique' => '海外仓名已存在']);
        $form->tools(function (Form\Tools $tools) {
            $tools->disableView();
            $tools->disableDelete();
        });
        return $form;
    }
}
